/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bear.fe.conn2;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author libear
 */
public class CTest {
 public static void testSave() throws FileException, InterruptedException{
       final byte[] bs = "hello,bear".getBytes(); 
       final byte[] bs1 = "hb1".getBytes();
       new Thread(){
           public void run() {
                try {
                    FileSystemConnection conn = FileSystemConnectionFactroy.getConnection();  
                    System.out.println("conn "+"save");
                    conn.saveFile("f:/ffde/temp/test1.txt", bs);
                    System.out.println("conn "+"save ok,sleep");
                    Thread.sleep(1000 * 15);
                    System.out.println("conn "+"commit");
                    conn.commit();
                } catch (InterruptedException ex) {
                    Logger.getLogger(CTest.class.getName()).log(Level.SEVERE, null, ex);
                } catch (FileException ex) {
                    Logger.getLogger(CTest.class.getName()).log(Level.SEVERE, null, ex);
                }
           }
       }.start();
       Thread.sleep(1000*3);
       new Thread(){
           public void run() {
                try {
                    FileSystemConnection conn1 = FileSystemConnectionFactroy.getConnection();
                    System.out.println("conn1 "+"save");
                    conn1.saveFile("f:/ffde/temp/test1.txt", bs1);
                    System.out.println("conn1 "+"save ok");
                    Thread.sleep(1);
                    conn1.commit();
                } catch (InterruptedException ex) {
                    Logger.getLogger(CTest.class.getName()).log(Level.SEVERE, null, ex);
                } catch (FileException ex) {
                    Logger.getLogger(CTest.class.getName()).log(Level.SEVERE, null, ex);
                }
           }
       }.start();
      
        ;
     }
 
 
 
 public static void testRemove() throws FileException, InterruptedException{
       final byte[] bs = "hello,bear".getBytes(); 
       FileSystemConnection temp = FileSystemConnectionFactroy.getConnection();
       temp.saveFile("f:/ffde/temp/test1.txt", bs);
       temp.commit();
       new Thread(){
           public void run() {
                try {
                    FileSystemConnection conn = FileSystemConnectionFactroy.getConnection(); 
                    System.out.println("conn "+" sleep");
                    Thread.sleep(1000 * 20);
                    byte[] bs = conn.getContent("f:/ffde/temp/test1.txt");
                    System.out.println("read content"+new String(bs));
                    conn.rollback();
                } catch (InterruptedException ex) {
                    Logger.getLogger(CTest.class.getName()).log(Level.SEVERE, null, ex);
                } catch (FileException ex) {
                    Logger.getLogger(CTest.class.getName()).log(Level.SEVERE, null, ex);
                }
           }
       }.start();
       Thread.sleep(1000*3);
       new Thread(){
           public void run() {
                try {
                    FileSystemConnection conn1 = FileSystemConnectionFactroy.getConnection();
                    System.out.println("conn1 "+"remove");
                    conn1.removeFile("f:/ffde/temp/test1.txt");
                    System.out.println("conn1 "+"remove ok");
                    Thread.sleep(1);
                    conn1.commit();
                } catch (InterruptedException ex) {
                    Logger.getLogger(CTest.class.getName()).log(Level.SEVERE, null, ex);
                } catch (FileException ex) {
                    Logger.getLogger(CTest.class.getName()).log(Level.SEVERE, null, ex);
                }
           }
       }.start();
      
        ;
     }
 
  public static void main(String[] args) throws Exception {
        // TODO code application logic here
        testRemove();
    }
}
